/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de La Frontera
 * License Type: Academic
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class AdministracionDAOImpl implements orm.dao.AdministracionDAO {
	public Administracion loadAdministracionByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return loadAdministracionByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion getAdministracionByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return getAdministracionByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return loadAdministracionByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion getAdministracionByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return getAdministracionByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Administracion) session.load(orm.Administracion.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion getAdministracionByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Administracion) session.get(orm.Administracion.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Administracion) session.load(orm.Administracion.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion getAdministracionByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Administracion) session.get(orm.Administracion.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryAdministracion(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return queryAdministracion(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryAdministracion(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return queryAdministracion(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion[] listAdministracionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return listAdministracionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion[] listAdministracionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return listAdministracionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryAdministracion(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Administracion as Administracion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryAdministracion(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Administracion as Administracion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion[] listAdministracionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		try {
			List list = queryAdministracion(session, condition, orderBy);
			return (Administracion[]) list.toArray(new Administracion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion[] listAdministracionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryAdministracion(session, condition, orderBy, lockMode);
			return (Administracion[]) list.toArray(new Administracion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return loadAdministracionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return loadAdministracionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Administracion[] administracions = listAdministracionByQuery(session, condition, orderBy);
		if (administracions != null && administracions.length > 0)
			return administracions[0];
		else
			return null;
	}
	
	public Administracion loadAdministracionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Administracion[] administracions = listAdministracionByQuery(session, condition, orderBy, lockMode);
		if (administracions != null && administracions.length > 0)
			return administracions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateAdministracionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return iterateAdministracionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateAdministracionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Trabajo3pdsPersistentManager.instance().getSession();
			return iterateAdministracionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateAdministracionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Administracion as Administracion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateAdministracionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Administracion as Administracion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion createAdministracion() {
		return new orm.Administracion();
	}
	
	public boolean save(orm.Administracion administracion) throws PersistentException {
		try {
			orm.Trabajo3pdsPersistentManager.instance().saveObject(administracion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Administracion administracion) throws PersistentException {
		try {
			orm.Trabajo3pdsPersistentManager.instance().deleteObject(administracion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Administracion administracion)throws PersistentException {
		try {
			orm.Cliente[] lClientes = administracion.cliente.toArray();
			for(int i = 0; i < lClientes.length; i++) {
				lClientes[i].setId_admin(null);
			}
			return delete(administracion);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Administracion administracion, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Cliente[] lClientes = administracion.cliente.toArray();
			for(int i = 0; i < lClientes.length; i++) {
				lClientes[i].setId_admin(null);
			}
			try {
				session.delete(administracion);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Administracion administracion) throws PersistentException {
		try {
			orm.Trabajo3pdsPersistentManager.instance().getSession().refresh(administracion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Administracion administracion) throws PersistentException {
		try {
			orm.Trabajo3pdsPersistentManager.instance().getSession().evict(administracion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Administracion loadAdministracionByCriteria(AdministracionCriteria administracionCriteria) {
		Administracion[] administracions = listAdministracionByCriteria(administracionCriteria);
		if(administracions == null || administracions.length == 0) {
			return null;
		}
		return administracions[0];
	}
	
	public Administracion[] listAdministracionByCriteria(AdministracionCriteria administracionCriteria) {
		return administracionCriteria.listAdministracion();
	}
}
